package com.floreo.shopping.service.impl;

import com.floreo.shopping.model.Product;
import com.floreo.shopping.model.Quantity;
import com.floreo.shopping.service.IQuantityService;

import java.util.*;

/**
 * @author merzod
 */
public class QuantityService implements IQuantityService {
    private Map<Product, List<Quantity>> quantities = new HashMap<Product, List<Quantity>>();

    @Override
    public List<Quantity> getQuantities(Product product) {
        return quantities.get(product);
    }

    @Override
    public void registerQuantities(Product product, Quantity... quantity) {
        if (quantity != null) {
            List<Quantity> list = quantities.get(product);
            if (list == null) {
                list = Arrays.asList(quantity);
                quantities.put(product, list);
            } else {
                list.addAll(Arrays.asList(quantity));
            }
        }
    }
}
